package com.zjw.algorithm.ready1;

import java.util.Stack;

public class _最小栈 {
}


class MinStack {

    private final Stack<Integer> stack = new Stack<>();

    private final Stack<Integer> minStack = new Stack<>();

    public MinStack() {

    }

    public void push(int val) {
        stack.push(val);

        if (minStack.isEmpty()) {
            minStack.push(val);
        } else if (minStack.peek() >= val) {
            minStack.push(val);
        }
    }

    public void pop() {
        int pop = stack.pop();

        if (!minStack.isEmpty()) {
            if (minStack.peek() == pop) {
                minStack.pop();
            }
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}